#pragma once

/*
it is a button by default
it only process basical events

to use a full button, you need to inherit it
and you can override the functions below:
	---------------------------------------
		determine_valid_region
		left_button_down
		left_button_up
		right_button_down
		right_button_up
		mouse_move
		mouse_leave
		key_down
		key_up
	---------------------------------------
you can also not override those functions
thus the behavior of the button is default
*/

class Button :public Control
{
protected:
	static const int STATE_NORMAL = 0;												//the button is unclicked nor passed
	static const int STATE_DOWN = 1;												//the button is clicked
	static const int STATE_MOVE = 2;												//the button is passed

protected:
	int state = STATE_NORMAL;														//preserve the button's state, initially normal

	Gdiplus::Color color_move = 0xaa546e7a;											//color of the button when cursor is passed
	Gdiplus::Color color_normal = 0xaa37474f;										//color of the button when nothing happens
	Gdiplus::Color color_down = 0xaa90a4ae;											//color of the button when clicked
	Gdiplus::Color color_font = 0xffffffff;											//color of the text

	std::wstring caption = L"Button";												//caption of the button

	Gdiplus::SolidBrush * brush_move;												//the brush to brush color_move
	Gdiplus::SolidBrush * brush_normal;												//the brush to brush color_normal
	Gdiplus::SolidBrush * brush_down;												//the brush to brush color_down
	Gdiplus::SolidBrush * brush_font;												//the brush to brush the font

	Gdiplus::FontFamily * ffm;														//fontfamily for the caption
	Gdiplus::Font * font;															//font of for the caption
	int clength;																	//unused
	int cheight;																	//unused

	std::wstring fontname = L"Consolas";											//fontname of the button
	int fontsize = 12;																//fontsize of the button

	void update_graphical();														//update every thing related to graphics
private:
	virtual void determine_valid_region() override;									//determine a region where events can be processed

protected:
	int left, top, width, height;													//specify the position of the button

public:
	Button(int left = 0, int top = 0, int width = 0, int height = 0);				//contructor
	~Button();																		//destructor

	virtual void draw(Gdiplus::Graphics & graphics) override;						//paint the button

	//events by default, should not be altered by client
	bool LButtonDown(int x, int y) override;
	bool LButtonUp(int x, int y) override;
	bool MouseMove(int button, int x, int y) override;
	bool MouseLeave(int button, int x, int y) override;

	//lots of get ans set functions-------------------------------------------
	Gdiplus::Color get_color_move() { return color_move; }
	Gdiplus::Color get_color_down() { return color_down; }
	Gdiplus::Color get_color_normal() { return color_normal; }
	Gdiplus::Color get_color_text() { return color_font; }
	void set_color_move(Gdiplus::Color color);
	void set_color_down(Gdiplus::Color color);
	void set_color_normal(Gdiplus::Color color);
	void set_color_text(Gdiplus::Color color);

	std::wstring get_caption() { return caption; }
	void set_caption(std::wstring caption);

	std::wstring get_fontname() { return fontname; }
	void set_fontname(std::wstring name);

	int get_fontsize() { return fontsize; }
	void set_fontsize(int size);
	//------------------------------------------------------------------------
};